﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CommunitySystem.Entity;
using System.Data;
using CommunitySystem.Model;

namespace CommunitySystem.BO.SystemManager
{
    public class SystemBO
    {
        public UserInfo Login(string LoginName, string PassWord, string DateString, string sig, bool NeedPasswordDog)
        {
            string sql = "select * from UserInfo where loginName='" + LoginName + "' and password='" + PassWord + "'";
            DataSet ds = AccessHelper.GetInstance().ExcuteDataSet(sql);
            if(ds.Tables[0].Rows.Count>0)
            {
                sql = "insert into CommunitySystemLoginStatistic (LoginName, LoginTime)  values ('" + LoginName + "', '" + DateTime.Now.ToShortDateString() + "')";
                CommunitySystem.BO.AccessHelper.GetInstance().ExecuteNonQuery(sql);
                var userinfo =  AccessHelper.FillDataRowToEntity<UserInfo>(ds.Tables[0], ds.Tables[0].Rows[0]);
                userinfo.Permissions = AccessHelper.GetInstance().GetEnity<PermissionBase>("OrgBaseID = " + userinfo.RoleID, "");
                return userinfo;
            }
            return null;
        }
    }
}
